﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using CP.Entities;
using CP.Repositories.GPM;
using CP.Utility;

namespace CP.Controllers.GPM
{
    public class EditUserInfoController
    {
        public EditUserInfoController()
        {
        }

        public IList<Department> GetAllDepts()
        {
            DepartmentRepository rep = new DepartmentRepository();
            return rep.GetAllDepts();
        }

        public IList<User_Group> GetAllGroups()
        {
            UserGroupRepository rep = new UserGroupRepository();
            return rep.GetAllUserGroups();
        }

        public User_Info GetUserInfo(string userid)
        {
            UserInfoRepository rep = new UserInfoRepository();
            return rep.GetUserByID(userid);
        }

        public bool AddUser(User_Info user)
        {
            UserInfoRepository rep = new UserInfoRepository();
            User_Info u = rep.GetUserByID(user.user_id);
            if (u.user_id != "")
                throw new Exception("用户ID=[" + user.user_id + "]已经存在！");
            rep.AddUser(user);
            return true;
        }

        public bool EditUser(User_Info user)
        {
            UserInfoRepository rep = new UserInfoRepository();
            User_Info u = rep.GetUserByID(user.user_id);
            if (u.user_id == "")
                throw new Exception("用户ID=[" + user.user_id + "]不存在！");
            rep.UpdateUser(user);
            return true;
        }
    }
}
